<template>
  <div>
    <!-- 我的频道 -->
    <div class="my-channel-box">
      <div class="channel-title">
        <span>已添加频道</span>
        <span>{{isEdit?'点击移除频道':'点击添加频道'}}</span>
        <span @click="isEdit=!isEdit">{{isEdit?'完成':'编辑'}}</span>
      </div>
      <!-- 我的频道列表 -->
      <van-row type="flex">
        <van-col span="6"
                 v-for="(arr,index) in list"
                 :key="arr.id"
                 @click="btn(arr,index)">
          <div class="channel-item van-hairline--surround">
            {{arr.name}}
            <!-- 删除的徽标 -->
            <van-badge color="transparent"
                       class="cross-badge">
              <template #content>
                <van-icon name="cross"
                          class="badge-icon"
                          color="#cfcfcf"
                          size="0.373334rem"
                          v-if="isEdit&& arr.id!==0" />
              </template>
            </van-badge>
          </div>
        </van-col>
      </van-row>
    </div>

    <!-- 更多频道 -->
    <div class="more-channel-box">
      <div class="channel-title">
        <span>点击添加更多频道：</span>
      </div>
      <!-- 更多频道列表 -->
      <van-row type="flex">
        <van-col span="6"
                 v-for="item in unchannelList"
                 :key="item.id"
                 @click="addFn(item)">
          <div class="channel-item van-hairline--surround">
            {{item.name}}
          </div>
        </van-col>
      </van-row>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    list: Array,
    unchannelList: Array
  },
  data () {
    return {
      isEdit: false
    }
  },
  methods: {
    // 我的頻道-点击事件
    btn (arr, index) {
      // 在恰当时机，向父组件传数据，删除数据
      // console.log(arr)
      // 只有点击编辑按钮才可以删除
      if (this.isEdit && arr.name !== '推荐') {
        this.$emit('edit', arr, index)
      } else {
        // 不是编辑状态，点击频道，进行跳转
        this.$emit('changeChannel', arr.id)
      }
    },
    // 更多频道-添加频道
    addFn (item) {
      // console.log(item)
      if (this.isEdit) {
        this.$emit('add', item)
      }
    }
  }
}
</script>

<style scoped lang="less">
.van-popup,
.popup-container {
  background-color: transparent;
  height: 100%;
  width: 100%;
}

.popup-container {
  display: flex;
  flex-direction: column;
}

.pop-header {
  height: 90px;
  background-color: #007bff;
  color: white;
  text-align: center;
  font-size: 14px;
  position: relative;
  .title {
    width: 100%;
    position: absolute;
    bottom: 15px;
  }
}

.pop-body {
  flex: 1;
  overflow: scroll;
  padding: 8px;
  background-color: white;
}

.my-channel-box,
.more-channel-box {
  .channel-title {
    display: flex;
    justify-content: space-between;
    font-size: 14px;
    line-height: 28px;
    padding: 0 6px;
  }
}

.channel-item {
  font-size: 12px;
  text-align: center;
  line-height: 36px;
  background-color: #fafafa;
  margin: 5px;
}

/*删除的微标 */
.cross-badge {
  position: absolute;
  right: -3px;
  top: 0;
  border: none;
}

/*提示文字 */
.small_title {
  font-size: 12px;
  color: gray;
}
</style>
